import { showToast } from "vant";
import { requestGet } from "@/utils/http";

const baseUrl = "/weixin";

export const getWxConfigApi = (data: { url: string }, showError = true) => {
  return requestGet<{
    appId: string;
    timestamp: number;
    noncestr: string;
    signature: string;
  }>(`${baseUrl}/get_wx_config`, data)
    .then((resp) => {
      return {
        appId: resp.appId,
        timestamp: `${resp.timestamp}`,
        nonceStr: resp.noncestr,
        signature: resp.signature,
      };
    })
    .catch((error: Error) => {
      showError && showToast(error.message);
      return Promise.reject(error);
    });
};
